using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUSLayer;

namespace QuanLyThuVien
{
    public partial class frmSuaSach : Form
    {
        public frmSuaSach()
        {
            InitializeComponent();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            try
            {
                int ma = int.Parse(txtMasach.Text);
                SachDto sach = new SachDto();
                sach=SachBus.TimKiem(ma);

                //Thong tin sach khong co trong CSDL
                if (sach == null)
                    MessageBox.Show("Khong co thong tin sach");
                else
                {
                    txtTensach.Text = sach.TENSACH;
                    txtMatacgia.Text = sach.MATACGIA.ToString();
                    txtMatheloai.Text = sach.MALOAISACH.ToString();
                    txtNXB.Text = sach.NAMXUATBAN.ToString();
                    txtGia.Text = sach.GIA.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }        
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Ban co that su muon sua", "Sua du lieu", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SachDto sach = new SachDto();

                    sach.MASACH = int.Parse(txtMasach.Text);
                    sach.MATACGIA = int.Parse(txtMatacgia.Text);
                    sach.TENSACH = txtTensach.Text;
                    sach.GIA = int.Parse(txtGia.Text);
                    sach.MALOAISACH = int.Parse(txtMatheloai.Text);

                    SachBus.Sua(sach);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Thoat_Click(object sender, EventArgs e)
        {
            Close();
        }

      
    }
}